package sample_queue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {
	// 队列名
	public final static String QUEUE_NAME = "sample_queue";

	public static void main(String[] args) throws Exception {
		// 工厂类
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost("mq.hinak0.xyz");
		factory.setUsername("admin");
		factory.setPassword("admin");
		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();
		channel.queueDeclare(QUEUE_NAME, false, false, false, null);
		for (int i = 0; i < 100; i++) {
			channel.basicPublish("", QUEUE_NAME, null, String.format("message %d", System.currentTimeMillis()).getBytes());
		}
		System.out.println("消息发送完毕");

		channel.close();
		connection.close();
	}
}